<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<textarea id="pos"></textarea>
<textarea id="nor"></textarea>
<textarea id="ind"></textarea>
<textarea id="result"></textarea>

<input type="button" onclick="stlToShadertoy()" />

</body>
<script>

    var triangleNum = 0;

    function stlToShadertoy() {
        var resultAyyay = [];
        resultAyyay = document.getElementById('pos').value.split(' ');


        var resultAyyayI = [];
        var Nset = document.getElementById('ind').value.split('<p>').shift();
        for(var i in Nset){
            var ar = Nset[i].split(' ');
            for(var ii in ar) {
                resultAyyayI.push(ar[ii].split('</p>')[0].trim());
            }
        }

        var resultAyyayN = [];
        resultAyyayN = document.getElementById('nor').value.split(' ');

        var resultStr = 'vec3 verts['+ resultAyyay.length/3 +'];\n';
        for(var i=0; i<resultAyyay.length/3; i++){
            resultStr += 'verts[' + i + '] = vec3('+ resultAyyay[i*3] +',' + resultAyyay[i*3+1] + ','+ resultAyyay[i*3+2] +');\n';
        }

        for(var trNum = 0; i<resultAyyayI.length/3; trNum++){
            resultStr += 'triangles[' + trNum + '].a = verts['+ resultAyyayI[trNum*3] +'];\n';
            resultStr += 'triangles[' + trNum + '].a = verts['+ resultAyyayI[trNum*3+1] +'];\n';
            resultStr += 'triangles[' + trNum + '].a = verts['+ resultAyyayI[trNum*3+2] +'];\n';

            var norIndex = trNum*3*3;
            resultStr += 'triangles[' + trNum + '].n = vec3('+ resultAyyayN[norIndex] +',' + resultAyyayN[norIndex+1] + ','+ resultAyyayN[norIndex+2] +');\n'

        }
        console.log(resultStr);
        document.getElementById('result').value = resultStr;
    }

</script>
</html>
